package br.com.foxinline.servico;

///*
// * To change this template, choose Tools | Templates
// * and open the template in the editor.
// */
//package br.com.foxline.service;
//
//import br.com.foxline.enums.Reports;
//import br.com.foxline.enums.Status;
//import br.com.foxline.enums.TypeAnnex;
//import br.com.foxline.enums.TypeDocument;
//import br.com.foxline.enums.TypeRequirement;
//import br.com.foxline.model.Annex;
//import br.com.foxline.model.Company;
//import br.com.foxline.model.People;
//import br.com.foxline.model.Physical;
//import br.com.foxline.model.Requirement;
//import br.com.foxline.util.Document;
//import br.com.foxline.util.Msg;
//import java.util.ArrayList;
//import java.util.Date;
//import java.util.HashMap;
//import java.util.List;
//import javax.ejb.EJB;
//import javax.ejb.Stateless;
//import javax.persistence.Query;
//
///**
// *
// * @author ely
// */
//@Stateless
//public class RequirementService extends GenericService<Requirement> {
//
//    @EJB
//    PeopleService peopleService;
//
//
//    public RequirementService() {
//        super(Requirement.class);
//    }
//
//    public void saveRequirement(Requirement requirement, List<Annex> annexs) {
//        try {
//            if (annexs.isEmpty()) {
//                requirement.setStatus(Status.DOCPENDENTE);
//            }
//            requirement.setAnnex(annexs);
//            requirement.setCreate_at(new Date());
//            returnTypeDoc(requirement);
//            save(requirement);
//            Msg.messagemInfo("Requerimento Salvo com Sucesso");
//        } catch (Exception erro) {
//        }
//    }
//
//    public void updateRequirement(Requirement requirement, List<Annex> annexs) {
//        try {
//            requirement.setAnnex(annexs);
//            update(requirement);
//            Msg.messagemInfo("Requerimento Atualizado com Sucesso");
//        } catch (Exception erro) {
//        }
//    }
//
//    public void returnTypeDoc(Requirement requirement) {
//        List<TypeAnnex> typeAnnexs = typeAnnex(requirement);
//        
//        List<TypeAnnex> typeAnnexNew = new ArrayList<TypeAnnex>();
//        for (Annex a : requirement.getAnnex()) {
//            typeAnnexNew.add(a.getType_annex());
//        }
//        if(typeAnnexNew.equals(typeAnnexs)){
//             requirement.setStatus(Status.IPTU_DESPACHO);
//        }else{
//             requirement.setStatus(Status.DOCPENDENTE);  
//        }
//       
//    }
//
//    public People existDocuments(People p) {
//        People pe;
//        pe = peopleService.existDocuments(p);
//        return pe;
//    }
//
//    public List<Annex> findAnnex(Requirement r) {
//        String sql = "SELECT a FROM Requirement r JOIN r.annex a WHERE r.id = :id";
//        Query query = getEntityManager().createQuery(sql);
//        query.setParameter("id", r.getId());
//        return (List<Annex>) query.getResultList();
//    }
//
//    public List<Requirement> findRequirement(Requirement req, People people) {
//        List<Requirement> reqs = new ArrayList<Requirement>();
//
//        String sql = "SELECT r FROM Requirement r ";
//
//        if (people.getTypeDocument() == TypeDocument.CPF) {
//            if ((!people.getCpf().equals("") && people.getCpf() != null)
//                    || (!people.getName().equals("") && people.getName() != null)) {
//                sql += " JOIN r.owner o ";
//
//            }
//        }
//        if (people.getTypeDocument() == TypeDocument.CNPJ) {
//            if ((!people.getCnpj().equals("") && people.getCnpj() != null)
//                    || (!people.getName_fantasy().equals("") && people.getName_fantasy() != null)) {
//                sql += " JOIN r.owner o ";
//
//            }
//        }
//
//
//        sql += " where ";
//
//
//
//        if (people.getTypeDocument() == TypeDocument.CPF) {
//            if ((!people.getCpf().equals("") && people.getCpf() != null)) {
//                sql += " lower(o.cpf) like lower(:cpf) and ";
//            }
//            if ((!people.getName().equals("") && people.getName() != null)) {
//                sql += " lower(o.name) like lower(:name) and ";
//            }
//        }
//
//        if (people.getTypeDocument() == TypeDocument.CNPJ) {
//            if ((!people.getCnpj().equals("") && people.getCnpj() != null)) {
//                sql += " lower(o.cnpj) like lower(:cnpj) and ";
//            }
//            if ((!people.getName_fantasy().equals("") && people.getName_fantasy() != null)) {
//                sql += " lower(o.name_fantasy) like lower(:namefantasy) and ";
//            }
//        }
//
//        if ((!req.getInterested().equals("")) && (req.getInterested() != null)) {
//            sql += " lower(r.interested) like lower(:interested) and  ";
//        }
//
//        if ((!"".equals(req.getProtocolo())) && (req.getProtocolo() != null)) {
//            sql += " lower(r.protocolo) like lower(:protocolo) and  ";
//        }
//
//        if ((req.getCreate_at() != null)) {
//            sql += " r.create_at = :date and  ";
//        }
//
//        sql += " 1=1 ";
//        System.err.print(sql);
//        Query query = getEntityManager().createQuery(sql);
//
//        if (people.getTypeDocument() == TypeDocument.CPF) {
//            if ((!people.getCpf().equals("") && people.getCpf() != null)) {
//                query.setParameter("cpf", people.getCpf());
//
//            }
//            if ((!people.getName().equals("") && people.getName() != null)) {
//                query.setParameter("name", "%" + people.getName() + "%");
//
//            }
//        }
//        if (people.getTypeDocument() == TypeDocument.CNPJ) {
//            if ((!people.getCnpj().equals("") && people.getCnpj() != null)) {
//                query.setParameter("cnpj", people.getCnpj());
//
//            }
//            if ((!people.getName_fantasy().equals("") && people.getName_fantasy() != null)) {
//                query.setParameter("namefantasy", "%" + people.getName_fantasy() + "%");
//
//            }
//        }
//
//        if ((!"".equals(req.getInterested())) && (req.getInterested() != null)) {
//            query.setParameter("interested", "%" + req.getInterested() + "%");
//        }
//        if ((!"".equals(req.getProtocolo())) && (req.getProtocolo() != null)) {
//            query.setParameter("protocolo", "%" + req.getProtocolo() + "%");
//        }
//        if ((req.getCreate_at() != null)) {
//            query.setParameter("date", req.getCreate_at());
//        }
//
//
//        reqs = query.getResultList();
//        return reqs;
//    }
//
//    public List<Requirement> findDispatchReq(Requirement req, People people) {
//        List<Requirement> reqs = new ArrayList<Requirement>();
//
//        String sql = "SELECT r FROM Requirement r ";
//
//
//
//        if (people.getTypeDocument() == TypeDocument.CPF) {
//            if ((!people.getCpf().equals("") && people.getCpf() != null)
//                    || (!people.getName().equals("") && people.getName() != null)) {
//                sql += " JOIN r.owner o ";
//
//            }
//        }
//        if (people.getTypeDocument() == TypeDocument.CNPJ) {
//            if ((!people.getCnpj().equals("") && people.getCnpj() != null)
//                    || (!people.getName_fantasy().equals("") && people.getName_fantasy() != null)) {
//                sql += " JOIN r.owner o ";
//
//            }
//        }
//
//
//        sql += " where ";
//
//
//
//        if (people.getTypeDocument() == TypeDocument.CPF) {
//            if ((!people.getCpf().equals("") && people.getCpf() != null)) {
//                sql += " lower(o.cpf) like lower(:cpf) and ";
//            }
//            if ((!people.getName().equals("") && people.getName() != null)) {
//                sql += " lower(o.name) like lower(:name) and ";
//            }
//        }
//
//        if (people.getTypeDocument() == TypeDocument.CNPJ) {
//            if ((!people.getCnpj().equals("") && people.getCnpj() != null)) {
//                sql += " lower(o.cnpj) like lower(:cnpj) and ";
//            }
//            if ((!people.getName_fantasy().equals("") && people.getName_fantasy() != null)) {
//                sql += " lower(o.name_fantasy) like lower(:namefantasy) and ";
//            }
//        }
//
//        if ((!req.getInterested().equals("")) && (req.getInterested() != null)) {
//            sql += " lower(r.interested) like lower(:interested) and  ";
//        }
//
//        if ((!"".equals(req.getProtocolo())) && (req.getProtocolo() != null)) {
//            sql += " lower(r.protocolo) like lower(:protocolo) and  ";
//        }
//
//        if ((req.getCreate_at() != null)) {
//            sql += " r.create_at = :date and  ";
//        }
//
//        sql += " r.status like(:IPTU_DESPACHO)  ";
//        System.err.print(sql);
//        Query query = getEntityManager().createQuery(sql);
//
//        if (people.getTypeDocument() == TypeDocument.CPF) {
//            if ((!people.getCpf().equals("") && people.getCpf() != null)) {
//                query.setParameter("cpf", people.getCpf());
//
//            }
//            if ((!people.getName().equals("") && people.getName() != null)) {
//                query.setParameter("name", "%" + people.getName() + "%");
//
//            }
//        }
//        if (people.getTypeDocument() == TypeDocument.CNPJ) {
//            if ((!people.getCnpj().equals("") && people.getCnpj() != null)) {
//                query.setParameter("cnpj", people.getCnpj());
//
//            }
//            if ((!people.getName_fantasy().equals("") && people.getName_fantasy() != null)) {
//                query.setParameter("namefantasy", "%" + people.getName_fantasy() + "%");
//
//            }
//        }
//
//        if ((!"".equals(req.getInterested())) && (req.getInterested() != null)) {
//            query.setParameter("interested", "%" + req.getInterested() + "%");
//        }
//        if ((!"".equals(req.getProtocolo())) && (req.getProtocolo() != null)) {
//            query.setParameter("protocolo", "%" + req.getProtocolo() + "%");
//        }
//        if ((req.getCreate_at() != null)) {
//            query.setParameter("date", req.getCreate_at());
//        }
//        query.setParameter("IPTU_DESPACHO", Status.IPTU_DESPACHO.name());
//
//
//        reqs = query.getResultList();
//        return reqs;
//    }
//
//    public List<TypeAnnex> typeAnnex(Requirement requirement) {
//        List<TypeAnnex> typeAnnexs = new ArrayList<TypeAnnex>();
//        if (requirement.getType_requeriment() == TypeRequirement.AVERBACAO) {
//            typeAnnexs.add(TypeAnnex.REGISTRO_IMOVEL);
//            typeAnnexs.add(TypeAnnex.ESCRITURA_PUBLICA);
//            typeAnnexs.add(TypeAnnex.ITBI);
//            typeAnnexs.add(TypeAnnex.PROCURACAO);
//            typeAnnexs.add(TypeAnnex.DOCUMENTOS_PESSOAIS);
//        }
//        if (requirement.getType_requeriment() == TypeRequirement.REVISAO_ALINHAMENTO) {
//            typeAnnexs.add(TypeAnnex.REGISTRO_IMOVEL);
//            typeAnnexs.add(TypeAnnex.PROCURACAO);
//            typeAnnexs.add(TypeAnnex.DOCUMENTOS_PESSOAIS);
//        }
//        if (requirement.getType_requeriment() == TypeRequirement.ALVARA_DESMEMBRAMENTO) {
//            typeAnnexs.add(TypeAnnex.REGISTRO_IMOVEL);
//            typeAnnexs.add(TypeAnnex.RG);
//            typeAnnexs.add(TypeAnnex.CPF);
//            typeAnnexs.add(TypeAnnex.ART);
//            typeAnnexs.add(TypeAnnex.COMPROVANTE_IPTU);
//            typeAnnexs.add(TypeAnnex.AVERBACAO);
//            typeAnnexs.add(TypeAnnex.REVISAO_ALINHAMENTO);
//
//        }
//        if (requirement.getType_requeriment() == TypeRequirement.ALVARA_REMEMBRAMENTO) {
//            typeAnnexs.add(TypeAnnex.REGISTRO_IMOVEL);
//            typeAnnexs.add(TypeAnnex.RG);
//            typeAnnexs.add(TypeAnnex.CPF);
//            typeAnnexs.add(TypeAnnex.ART);
//            typeAnnexs.add(TypeAnnex.COMPROVANTE_IPTU);
//            typeAnnexs.add(TypeAnnex.AVERBACAO);
//            typeAnnexs.add(TypeAnnex.REVISAO_ALINHAMENTO);
//        }
//        if (requirement.getType_requeriment() == TypeRequirement.HABITE) {
//            typeAnnexs.add(TypeAnnex.RG);
//            typeAnnexs.add(TypeAnnex.CPF);
//            typeAnnexs.add(TypeAnnex.ART);
//        }
//        if (requirement.getType_requeriment() == TypeRequirement.ALVARA_DEMOLICAO) {
//            typeAnnexs.add(TypeAnnex.ALVARA_CONSTRUCAO);
//            typeAnnexs.add(TypeAnnex.PLANTA_ASSINADA);
//            typeAnnexs.add(TypeAnnex.REGISTRO_IMOVEL);
//            typeAnnexs.add(TypeAnnex.RG);
//            typeAnnexs.add(TypeAnnex.CPF);
//            typeAnnexs.add(TypeAnnex.ART);
//            typeAnnexs.add(TypeAnnex.CONTRATO_CONSTRUTORA);
//            typeAnnexs.add(TypeAnnex.REGISTRO_IMOVEL);
//            typeAnnexs.add(TypeAnnex.COMPROVANTE_IPTU);
//            typeAnnexs.add(TypeAnnex.AVERBACAO);
//            typeAnnexs.add(TypeAnnex.REVISAO_ALINHAMENTO);
//        }
//        if (requirement.getType_requeriment() == TypeRequirement.ALVARA_CONSTRUCAO) {
//            typeAnnexs.add(TypeAnnex.ALVARA_CONSTRUCAO);
//            typeAnnexs.add(TypeAnnex.PLANTA_ASSINADA);
//            typeAnnexs.add(TypeAnnex.REGISTRO_IMOVEL);
//            typeAnnexs.add(TypeAnnex.RG);
//            typeAnnexs.add(TypeAnnex.CPF);
//            typeAnnexs.add(TypeAnnex.ART);
//            typeAnnexs.add(TypeAnnex.CONTRATO_CONSTRUTORA);
//            typeAnnexs.add(TypeAnnex.REGISTRO_IMOVEL);
//            typeAnnexs.add(TypeAnnex.COMPROVANTE_IPTU);
//            typeAnnexs.add(TypeAnnex.AVERBACAO);
//            typeAnnexs.add(TypeAnnex.REVISAO_ALINHAMENTO);
//        }
//        if (requirement.getType_requeriment() == TypeRequirement.ALVARA_REGULARIZACAO_OBRA_CONSTRUIDA) {
//            typeAnnexs.add(TypeAnnex.ALVARA_CONSTRUCAO);
//            typeAnnexs.add(TypeAnnex.PLANTA_ASSINADA);
//            typeAnnexs.add(TypeAnnex.REGISTRO_IMOVEL);
//            typeAnnexs.add(TypeAnnex.RG);
//            typeAnnexs.add(TypeAnnex.CPF);
//            typeAnnexs.add(TypeAnnex.ART);
//            typeAnnexs.add(TypeAnnex.CONTRATO_CONSTRUTORA);
//            typeAnnexs.add(TypeAnnex.REGISTRO_IMOVEL);
//            typeAnnexs.add(TypeAnnex.COMPROVANTE_IPTU);
//            typeAnnexs.add(TypeAnnex.AVERBACAO);
//            typeAnnexs.add(TypeAnnex.REVISAO_ALINHAMENTO);
//        }
//        if (requirement.getType_requeriment() == TypeRequirement.ALVARA_RETIFICACAO_ALVARA) {
//            typeAnnexs.add(TypeAnnex.ALVARA_CONSTRUCAO);
//            typeAnnexs.add(TypeAnnex.PLANTA_ASSINADA);
//            typeAnnexs.add(TypeAnnex.REGISTRO_IMOVEL);
//            typeAnnexs.add(TypeAnnex.RG);
//            typeAnnexs.add(TypeAnnex.CPF);
//            typeAnnexs.add(TypeAnnex.ART);
//            typeAnnexs.add(TypeAnnex.CONTRATO_CONSTRUTORA);
//            typeAnnexs.add(TypeAnnex.REGISTRO_IMOVEL);
//            typeAnnexs.add(TypeAnnex.COMPROVANTE_IPTU);
//            typeAnnexs.add(TypeAnnex.AVERBACAO);
//            typeAnnexs.add(TypeAnnex.REVISAO_ALINHAMENTO);
//        }
//
//        return typeAnnexs;
//    }
//
//    public void reportsRequirement(Requirement req, HashMap parametros) {
//        ReportService.genReport(parametros, null, Reports.REQUIREMENT);
//    }
//}
